package cn.wolfcode.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;

@Component
public class JwtUtlis {
    private static  String miyao = "xiaozhi";
    private static Long time = 3600 *1000 *24L;

    public static String createJwt(HashMap<String,Object> Claims){
        return Jwts.builder()
                .addClaims(Claims)
                .setExpiration(new Date(System.currentTimeMillis() + time))
                .signWith(io.jsonwebtoken.SignatureAlgorithm.HS256, miyao)
                .compact();
    }

    public static Claims parseJwt(String jwt){
        return Jwts.parser()
                .setSigningKey(miyao)
                .parseClaimsJws(jwt)
                .getBody();
    }
}
